Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses a SQLite database connection error (CANTOPEN errno:14) by introducing a configurable database path via the DB_PATH environment variable and adjusting the Docker configuration.
Key changes:
- Added
DB_PATHenvironment variable support in the TypeORM DataSource configuration with fallback to "data.db" - Modified docker-compose.yml to set DB_PATH and changed volume mapping from file-based to directory-based
- Updated README documentation with DB_PATH configuration instructions
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/dataSource.ts | Added DB_PATH environment variable support with fallback for database path configuration |
| docker-compose.yml | Added DB_PATH environment variable and changed volume mapping from ./data.db to ./data directory |
| README.md | Documented the new DB_PATH environment variable in the setup instructions |
| Dockerfile | Changed base image from node:20-alpine to node:20-slim |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| environment: | ||
| - TELEGRAM_TOKEN=${TELEGRAM_TOKEN} | ||
| - WEBAPP_URL=${WEBAPP_URL} | ||
| - DB_PATH=/app/data.db |
There was a problem hiding this comment.
There's a trailing space after the DB_PATH value. Remove the space at the end of this line to avoid potential issues with the environment variable value.
| - DB_PATH=/app/data.db | |
| - DB_PATH=/app/data.db |
| export const AppDataSource = new DataSource({ | ||
| type: "sqlite", | ||
| database: "data.db", | ||
| database: process.env.DB_PATH || "data.db", |
There was a problem hiding this comment.
There's extra spacing between 'database:' and 'process.env.DB_PATH'. While this doesn't affect functionality, it's inconsistent with the typical code style. Consider using a single space for consistency.
| database: process.env.DB_PATH || "data.db", | |
| database: process.env.DB_PATH || "data.db", |
| ```env | ||
| TELEGRAM_TOKEN=your_telegram_bot_token | ||
| WEBAPP_URL=http://localhost:5000 | ||
| DB_PATH=/path/to/data/data.db # use in development mode (not needed for docker-compose setup) |
There was a problem hiding this comment.
The documentation suggests using an absolute path like "/path/to/data/data.db" but this might be confusing. For local development, the path should typically be relative to the project root (e.g., "./data/data.db" or an absolute path using __dirname). Consider clarifying the expected path format or providing a concrete example that users can actually use.
| DB_PATH=/path/to/data/data.db # use in development mode (not needed for docker-compose setup) | |
| DB_PATH=./data/data.db # путь к файлу БД относительно корня проекта (для локальной разработки; не нужен для docker-compose) |
| @@ -1,4 +1,4 @@ | |||
| FROM node:20-alpine | |||
| FROM node:20-slim | |||
There was a problem hiding this comment.
The Dockerfile doesn't create the /app/data directory that's needed for the database file when using DB_PATH=/app/data.db. Consider adding 'RUN mkdir -p /app/data' before the CMD instruction to ensure the directory exists when the container starts.
| environment: | ||
| - TELEGRAM_TOKEN=${TELEGRAM_TOKEN} | ||
| - WEBAPP_URL=${WEBAPP_URL} | ||
| - DB_PATH=/app/data.db |
There was a problem hiding this comment.
There's a mismatch between the DB_PATH environment variable and the volume mapping. DB_PATH is set to /app/data.db but the volume maps ./data to /data (not /app/data). This will cause the database file to be created at /app/data.db inside the container, which won't be persisted to the host because the volume is mounted at /data. Either change DB_PATH to /data/data.db or change the volume mapping to ./data:/app/data.
| - DB_PATH=/app/data.db | |
| - DB_PATH=/data/data.db |
When running 'npm run dev' or 'docker compose up --build' command I received 'SQLITE CANTOPEN errorno:14' error. This was caused because DataSource class in dataSource.ts couldn't find the database file.
Proposed fix: add DB_PATH environment variable that is resolved to the absolute path of the project (should be set in .env file). Also added in 'environment' section in docker-compose.yml so that when app is launched using 'docker compose up --build' command, docker get the path from DB_PATH variable in 'docker-compose.yml'.
Node image was changed in Dockerfile from node:20-alpine to node:20-slim because node:20-alpine bugged.
Tested on Linux Ubuntu.